//
//  MainViewController.m
//  BCall20150922
//
//  Created by longziyuan on 14-10-18.
//
//

#import "MainViewController.h"
#import "GlobalVar.h"
@interface MainViewController ()

@end


@implementation MainViewController
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

/*
-(void)checkDownloadAddress:(NSString*)url
{
    
    
    net_work=[[NewNetWork alloc]init];
    [net_work setDelegate:self];
    
    [net_work getNetUrl:url CanShu:nil];
    
}
*/

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    mainView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H)]autorelease];
    NSData* lauchData=[[NSUserDefaults standardUserDefaults] objectForKey:@"launchData"];
    if (lauchData!=nil) {
        mainView.image=[UIImage imageWithData:lauchData];
        //[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageWithData:lauchData]]];
    }else
    {
        mainView.image=[UIImage imageNamed:@"Main.png"];
        //[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Main.png"]]];
    }
    [self.view addSubview:mainView];
    UILabel *labVer = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-40, self.view.frame.size.height/2+100, 80, 50)];
    labVer.text= [GlobalVar getVersion];
    labVer.enabled=false;
    labVer.adjustsFontSizeToFitWidth = YES;
    labVer.baselineAdjustment=UIBaselineAdjustmentAlignCenters;
    [self.view addSubview:labVer];
    [labVer setTextColor:[UIColor redColor]];
    //[self performSelector:@selector(goToSoft) withObject:nil afterDelay:2.0f];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   // [self checkDownloadAddress:SOFT_TEST_DOWNLOAD_URL];

}
/*
-(void)goToSoft
{
    if (delegate) {
        [delegate enterSoft];
    }
}
*/
-(void)setLauchIm:(UIImage*)image
{
    mainView.image=image;
}

-(void)getTheAnalysizeResults:(NSString *)result
{
    NSLog(@"check downloadAddress is valid:%@",result);
    
    
    if ([result isEqualToString:@"ok"]) {
        NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:ORIGINAL_DOWNLOAD_ADDRESS  forKey:@"downloadAddress"];
        [defaults synchronize];
    }

    
    if (net_work!=nil) {
        [net_work release];
        net_work=nil;
    }

}

-(void)getFailResults:(NSString *)errorResult
{
    NSLog(@"error download address:%@",errorResult);
    NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject:SOFT_ZHONGZHUAN_DOWNLOAD_URL forKey:@"downloadAddress"];
    [defaults synchronize];
    
    
    if (net_work!=nil) {
        [net_work release];
        net_work=nil;
    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
